2020-2021 Sunseeker Telemetry and Lighting System
eusci_a_uart_ex1_loopbackAdvanced.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
61 //******************************************************************************
62 #include "driverlib.h"
63 #include "Board.h"
64 
65 uint16_t i;
66 uint8_t RXData = 0, TXData = 0;
67 uint8_t check = 0;
68 
69 void main(void)
70 {
71  //Stop Watchdog Timer
72  WDT_A_hold(WDT_A_BASE);
73 
74  //Set ACLK = REFOCLK with clock divider of 1
75  CS_initClockSignal(CS_ACLK,CS_REFOCLK_SELECT,CS_CLOCK_DIVIDER_1);
76  //Set SMCLK = DCO with frequency divider of 1
77  CS_initClockSignal(CS_SMCLK,CS_DCOCLKDIV_SELECT,CS_CLOCK_DIVIDER_1);
78  //Set MCLK = DCO with frequency divider of 1
79  CS_initClockSignal(CS_MCLK,CS_DCOCLKDIV_SELECT,CS_CLOCK_DIVIDER_1);
80 
81  //Configure UART pins
82  GPIO_setAsPeripheralModuleFunctionInputPin(
83  GPIO_PORT_UCA0TXD,
84  GPIO_PIN_UCA0TXD,
85  GPIO_FUNCTION_UCA0TXD
86  );
87  GPIO_setAsPeripheralModuleFunctionInputPin(
88  GPIO_PORT_UCA0RXD,
89  GPIO_PIN_UCA0RXD,
90  GPIO_FUNCTION_UCA0RXD
91  );
92 
93  /*
94  * Disable the GPIO power-on default high-impedance mode to activate
95  * previously configured port settings
96  */
97  PMM_unlockLPM5();
98 
99  //Configure UART
100  //SMCLK = 1MHz, Baudrate = 115200
101  //UCBRx = 8, UCBRFx = 0, UCBRSx = 0xD6, UCOS16 = 0
102  EUSCI_A_UART_initParam param = {0};
103  param.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK;
104  param.clockPrescalar = 8;
105  param.firstModReg = 0;
106  param.secondModReg = 0xD6;
107  param.parity = EUSCI_A_UART_NO_PARITY;
108  param.msborLsbFirst = EUSCI_A_UART_LSB_FIRST;
109  param.numberofStopBits = EUSCI_A_UART_ONE_STOP_BIT;
110  param.uartMode = EUSCI_A_UART_MODE;
111  param.overSampling = EUSCI_A_UART_LOW_FREQUENCY_BAUDRATE_GENERATION;
112 
113  if (STATUS_FAIL == EUSCI_A_UART_init(EUSCI_A0_BASE, &param)) {
114  return;
115  }
116 
117  EUSCI_A_UART_enable(EUSCI_A0_BASE);
118 
119  EUSCI_A_UART_clearInterrupt(EUSCI_A0_BASE,
120  EUSCI_A_UART_RECEIVE_INTERRUPT);
121 
122  // Enable USCI_A0 RX interrupt
123  EUSCI_A_UART_enableInterrupt(EUSCI_A0_BASE,
124  EUSCI_A_UART_RECEIVE_INTERRUPT);
125 
126  // Enable global interrupts
127  __enable_interrupt();
128  while (1)
129  {
130  // Increment TX data
131  TXData = TXData+1;
132  // Load data onto buffer
133  EUSCI_A_UART_transmitData(EUSCI_A0_BASE, TXData);
134  while(check != 1);
135  check = 0;
136  }
137 }
138 //******************************************************************************
139 //
140 //This is the USCI_A0 interrupt vector service routine.
141 //
142 //******************************************************************************
143 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
144 #pragma vector=USCI_A0_VECTOR
145 __interrupt
146 #elif defined(__GNUC__)
147 __attribute__((interrupt(USCI_A0_VECTOR)))
148 #endif
149 void EUSCI_A0_ISR(void)
150 {
151  switch(__even_in_range(UCA0IV,USCI_UART_UCTXCPTIFG))
152  {
153  case USCI_NONE: break;
154  case USCI_UART_UCRXIFG:
155  RXData = EUSCI_A_UART_receiveData(EUSCI_A0_BASE);
156  // Check value
157  if(!(RXData == TXData))
158  {
159  while(1);
160  }
161  check =1;
162  break;
163  case USCI_UART_UCTXIFG: break;
164  case USCI_UART_UCSTTIFG: break;
165  case USCI_UART_UCTXCPTIFG: break;
166  }
167 }
168 
void EUSCI_A0_ISR(void)
MPU_initThreeSegmentsParam param
#define STATUS_FAIL
Definition: hw_memmap.h:23